<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: personal_links.php 87 2013-09-21 12:04:05Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 87 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:04:05 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
require(DIR_FS_INC.'inc.get_url_friendly_text.php');

$languages = get_languages();

if(isset($_POST['action']) && ($_POST['action'] == 'save' ) && (!empty($_POST['file_name'])) && (!empty($_POST['url_text'])) || isset($_POST['action']) && ($_POST['action'] == 'save_new' ) && (!empty($_POST['file_name'])) && (!empty($_POST['url_text']))) {

	$url = strtolower($_POST['url_text']);
	$url = get_url_friendly_text($url);
	$url = trim(str_replace('html','',$url));
	$url = str_replace('php','',$url);

	if(isset($_POST['code']) && MODULE_SEO_URL_INDEX_LANGUAGEURL=='True')
		$url = $_POST['code'].'/'.$url;

	$sql_data_array = array ('url_text' => $url,
							'file_name' => $_POST['file_name'],
							'language_id' => $_POST['l']);

	if($_POST['action'] == 'save')
		$db->db_perform(TABLE_PERSONAL_LINKS_URL, $sql_data_array, 'update', 'file_name = \''.$_POST['file_name'].'\' AND language_id = \''.$_POST['l'].'\'');

	elseif($_POST['action'] == 'save_new')
		$db->db_perform(TABLE_PERSONAL_LINKS_URL, $sql_data_array);
	
	redirect(href_link(FILENAME_PERSONAL_LINKS.'#language_'.$_POST['l']));

} elseif($_GET['action'] == 'new_personal_url') {
	if(!empty($_POST['file_name']) && !empty($_POST['file_name_php'])) {
		$sql_data_array = array ('file_name' => strtoupper($_POST['file_name']),
								'file_name_php' => $_POST['file_name_php']);
		$db->db_perform('seo_url_names', $sql_data_array);
		redirect(href_link(FILENAME_PERSONAL_LINKS));

	} else {
		$message_stack->add('Geben Sie eine Dateikonstante und einen Dateinamen an.', 'error');
		redirect(href_link(FILENAME_PERSONAL_LINKS, 'action=new_link'));
	}

} elseif($_GET['action'] == 'delete_link') {
	if($_GET['id'] != '')
		$db->db_query("DELETE FROM ".TABLE_PERSONAL_LINKS_URL." WHERE link_id = '".(int)$_GET['id']."' AND language_id = '".$_GET['l']."' ");
		redirect(href_link(FILENAME_PERSONAL_LINKS, '#language_'.$_GET['l']));

} elseif($_GET['action'] == 'robots') {
	
	$query_names = array('*mercari=*',
						'*view_as=*',
						'*per_site=*',
						'*multisort=*',
						'*qty=*',
						'*linkurl=*');
	
	$file_names = array('address_book.php',
						'address_book_process.php',
						'account.php',
						'account_edit.php',
						'account_edit_process.php',
						'account_history.php',
						'account_history_info.php',
						'checkout_process.php',
						'advanced_search.php',
						'advanced_search_result.php',
						'checkout.php',
						'checkout_address.php',
						'checkout_confirmation.php',
						'checkout_payment.php',
						'checkout_payment_address.php',
						'checkout_shipping.php',
						'checkout_shipping_address.php',
						'checkout_success.php',
						'cookie_usage.php',
						'contact_us.php',
						'create_account.php',
						'create_account_guest.php',
						'create_account_process.php',
						'css_styler.php',
						'captcha.php',
						'download.php',
						'fax.html',
						'getCountry.php',
						'gv_redeem.php',
						'gv_send.php',
						'java.js.php',
						'login.php',
						'login_offline.php',
						'logoff.php',
						'mercari_img.php',
						'newsletter.php',
						'password_double_opt.php',
						'popup_search_help.php',
						'print_product_info.php',
						'print_order.php',
						'print_pdf.php',
						'popup_content.php',
						'product_filter.php',
						'product_reviews.php',
						'product_reviews_info.php',
						'product_reviews_write.php',
						'reviews.php',
						'seo_url.php',
						'seo_url_cronjob.php',
						'shopping_cart.php',
						'style.css.php');
						
	$folder_names = array('admin/',
						'callback/',
						'cache/',
						'callback/',
						'download/',
						'export/',
						'import/',
						'inc/',
						'includes/',
						'installer/',
						'keywords/',
						'lang/',
						'media/content/',
						'pub/',
						'templates_c/');

    $file_name = DIR_FS_CATALOG.'cache/robots.txt';
        
    $robots  = 'User-agent: *'."\n";
    
    foreach($query_names AS $names)
        $robots .= 'Disallow: '.DIR_WS_CATALOG.$names."\n"; 
          
    foreach($file_names AS $names)
        $robots .= 'Disallow: '.DIR_WS_CATALOG.$names."\n";

    if(MODULE_SEO_URL_INDEX_STATUS == 'True') {
	    // PHP-Dateien der Personal-Links zusammen suchen die sowieso raus müssen
	    $pl = $db->db_query("SELECT
								supl.file_name,
								supl.url_text,
								supl.language_id,
								supn.file_name,
								supn.file_name_php
							FROM 
								".TABLE_PERSONAL_LINKS_NAMES." AS supn,
								".TABLE_PERSONAL_LINKS_URL." AS supl 
							WHERE
								supl.file_name = supn.file_name 
							AND 
								supl.language_id = '".$_SESSION['languages_id']."'
							AND
								supl.url_text !=''
							AND
								supn.file_name_php IN ('".implode('\',\'', $file_names)."')
							ORDER BY 
								supn.file_name ASC");
	    
	    if($pl->_numOfRows) {
	    	$robots .= 'Disallow: /*keywords=*'."\n";
	    	$robots .= 'Disallow: /*tag=*'."\n";
	    	
	    	$robots .= 'Disallow: /index.php'."\n";
	    	$robots .= 'Disallow: /product_info.php'."\n";
	    	$robots .= 'Disallow: /products_new.php'."\n";
	    	$robots .= 'Disallow: /reviews.php'."\n";
	    	$robots .= 'Disallow: /specials.php'."\n";
	    	$robots .= 'Disallow: /taglisting.php'."\n";
	    	$robots .= 'Disallow: /wish_list.php'."\n";
	    	$robots .= 'Disallow: /pdfbill.php'."\n";
	    	
	    	while(!$pl->EOF) {
	    		$robots .= 'Disallow: '.DIR_WS_CATALOG.$pl->fields['url_text'].'.html'."\n";
	    		$pl->MoveNext();
	    	}
	    }
    }
    
    foreach($folder_names AS $names)
        $robots .= 'Disallow: '.DIR_WS_CATALOG.$names."\n";
    
    $robots .= 'Sitemap: '.HTTP_SERVER.DIR_WS_CATALOG.'sitemap.xml.php'."\n";
    $robots .= 'Sitemap: '.HTTP_SERVER.DIR_WS_CATALOG.'sitemap_images.xml.php'."\n";

    file_put_contents($file_name, $robots);
    $message_stack->add_session(ROBOTS_CREATED, 'success');
    redirect(href_link(FILENAME_PERSONAL_LINKS,'#language_'.$_GET['l']));
}

require(DIR_WS_INCLUDES.'metatag.php');
?>
<script type="text/javascript">
<!--
	$(function(){$('#tabs').tabs({fx:{opacity:'toggle'}});});
//-->
</script>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
	<table class="outerTable">
		<tr>
			<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
				<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
			</td>
			<td valign="top">
		<table border="0" width="100%" cellspacing="2" cellpadding="2">
		  <tr>
		    <td class="boxCenter" width="100%" valign="top">
		      <table border="0" width="100%" cellspacing="0" cellpadding="0">
		      	<tr>
		      		<td colspan="3">
		      			<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
					    <tr>
					     <td class="pageHeading">
					        Personal URL Links <?php echo get_help(11, 'Personal URL - Manager'); ?>
					     </td>
					   </tr>
					   </table>
		      		</td>
		      	</tr>
		        <tr>
		        <td align="left">

				<?php
					if(isset($_GET['action']) && $_GET['action'] == 'new_link' ) {
					echo draw_form('new_personal_url', FILENAME_PERSONAL_LINKS, 'action=new_personal_url')
				?>
		        	<table class="dataTable" width="100%">
		        		<tr class="dataTableHeadingRow">
	                    	<th class="dataTableHeadingContent" height="20">Datei Konstante</th>
	                        <th class="dataTableHeadingContent" height="20">Datei Name</th>
	                        <th class="dataTableHeadingContent" align="left" height="20">&nbsp;</th>
	                    </tr>
						<tr>
							<td>
								<?php echo draw_input_field('file_name', '', 'size="30"') ?>
							</td>
							<td>
								<?php echo draw_input_field('file_name_php', '', 'size="30"') ?>
							</td>
							<td>
								<?php echo '<input type="submit" class="button" value="Speichern" />
										<a class="button" href="'.href_link(FILENAME_PERSONAL_LINKS, getMenuID('personal_links').'#language_'.$languages[$i]['id']).'">Abbruch</a>'; ?>
							</td>
						</tr>
					</table>
					</form>
				<?php } else { ?>
					<div align="right">
						<a class="button" href="<?php echo href_link(FILENAME_PERSONAL_LINKS, 'action=new_link'); ?>">Neuer Personal Link</a> 
						<a class="button" href="<?php echo href_link(FILENAME_PERSONAL_LINKS, 'action=robots'); ?>">robots.txt erzeugen</a>
					</div>
					<div id="tabs">
		  				<ul>
		  					<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
						    	<li><a href="#language_<?php echo $languages[$i]['id']; ?>">
						    		<span><img src="../lang/<?php echo $languages[$i]['directory'].'/'.$languages[$i]['image']; ?>" alt="" /> <?php echo $languages[$i]['name'] ?></span>
						    	</a></li>
						    <?php } ?>
		  				</ul>
				        <?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
				        	<div id="language_<?php echo $languages[$i]['id']; ?>">
					        	<table class="dataTable" width="100%">
					        		<tr class="dataTableHeadingRow">
				                    	<th class="dataTableHeadingContent" height="20" width="30">&nbsp;</th>
				                        <th class="dataTableHeadingContent" height="20">URL</th>
				                        <th class="dataTableHeadingContent" align="left" height="20">Beschreibung</th>
				                        <th class="dataTableHeadingContent">&nbsp;</th>
				                    </tr>
				        			<?php
										$pl = $db->db_query("	SELECT 
																	cp.url_text,
																	cp.link_id,
																	cp.file_name,
																	cp.language_id,
																	cn.file_name,
																	cn.file_name_php
																FROM 
																	".TABLE_PERSONAL_LINKS_NAMES." AS cn
																LEFT OUTER JOIN
																	".TABLE_PERSONAL_LINKS_URL." AS cp 
																	ON 
																		(cp.file_name = cn.file_name 
																	AND 
																		cp.language_id = '".$languages[$i]['id']."')
																ORDER BY 
																	cn.file_name ASC");

										while(!$pl->EOF) { ?>
										<tr>
											<td align="center" width="5%">
												<?php
													echo '<a href="'.href_link(FILENAME_PERSONAL_LINKS,'action=edit_link&id='.$pl->fields['file_name_php'].'&l='.$languages[$i]['id'].'#language_'.$languages[$i]['id']).'">
															'.image(DIR_WS_IMAGES.'icon_edit.gif').
														'</a>';
												?>
											</td>
											<td width="40%" nowrap="nowrap">
												<?php

													if(isset($_GET['action']) && ($_GET['action'] == 'edit_link') && ($_GET['id'] == $pl->fields['file_name_php']) && ($_GET['l'] == $languages[$i]['id'])) {
														$url_text = str_replace($languages[$i]['code'].'/','',$pl->fields['url_text']);
														echo draw_form('edit_personal_url', FILENAME_PERSONAL_LINKS, '', 'post', '')
																.draw_hidden_field('file_name',$pl->fields['file_name'])
																.draw_hidden_field('l',$languages[$i]['id']);
														if(MODULE_SEO_URL_INDEX_LANGUAGEURL=='True')
															echo draw_hidden_field('code',$languages[$i]['code']);
														if(empty($pl->fields['url_text']))
															echo draw_hidden_field('action','save_new');
														else
															echo draw_hidden_field('action','save');
														echo draw_input_field('url_text', $url_text, 'size="30"').'.html <input type="submit" class="button" value="Speichern" />
																<a class="button" href="'.href_link(FILENAME_PERSONAL_LINKS,getMenuID('personal_links').'#language_'.$languages[$i]['id']).'">Abbruch</a>';
														echo '</form>';
													} else {
														if(!empty($pl->fields['url_text']))
															echo $pl->fields['url_text'].'.html';
														else
															echo '-';
													}
												?>
											</td>
											<td class="last" width="55%">
												<?php
													echo constant(strtoupper($pl->fields['file_name'].'_DESC'));
												?>
											</td>
											<td width="1">
												<?php
												if(!empty($pl->fields['url_text']))
													echo '<a href="'.href_link(FILENAME_PERSONAL_LINKS,'action=delete_link&id='.$pl->fields['link_id'].'&l='.$languages[$i]['id'].'#language_'.$languages[$i]['id']).'">'.image(DIR_WS_ICONS.'chain--minus.png', $pl->fields['url_text'].' l&ouml;schen'). '</a>';
												?>
											</td>
										</tr>
									<?php $pl->MoveNext();} ?>
				        		</table>
				        	</div>
			        	<?php }
						}
						?>
		        	</td>
		        </tr>
		      </table></td>
		  </tr>
		</table>
	</td>
	</tr>
	</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>